package com.zw.a.basic.a09.demo02_integer;

//案例: 演示int和String之间的相互转换.
public class Demo02 {
    public static void main(String[] args) {
        //需求1: int   ->     String
        //方式一: 直接在数值后边拼接 "",        推荐使用.
        int a = 10;
        String s1 = a + "";
        System.out.println("s1: " + s1);

        //方式二: String#valueOf()
        String s2 = String.valueOf(111);
        System.out.println("s2: " + s2);
        System.out.println("-----------------------------");

        //需求2: String   ->     int
        //方式1: 转换思路 String -> Integer -> int
        String s3 = "123";
        //String -> Integer
        Integer i1 = new Integer(s3);
        //Integer -> int
        int num1 = i1.intValue();
        System.out.println("num1: " + num1);

        //方式2: 通过Integer#parseInt();方法实现,  推荐使用.
        int num2 = Integer.parseInt(s3);
        System.out.println("num2: " + num2);

    }
}
